﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Castle.ActiveRecord;
using Demo.Model;
using Pampa.MVC.Models;

namespace Pampa.MVC.Controllers
{
    public class CustomerController : Controller
    {
        public ActionResult Grid()
        {
            return View();
        }

        public ActionResult Edit(int id)
        {
            ViewBag.Customer = Customer.Find(id);
            return View();
        }

        public ActionResult New()
        {
            ViewBag.Customer = new Customer();
            return View("Edit");
        }

        public ActionResult Delete(int id)
        {
            try
            {
                Customer.Find(id).Delete();
                return Json( new object{});
            }
            catch (Exception)
            {
                return Json(new {error = "Unexpected error trying to delete the customer"});
            }
        }
    }
}
